home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / printing / nenscrip.000 / nenscrip / nenscript-1.13++ / print.c < prev    next >
C/C++ Source or Header  |  1992-11-24  |  2KB  |  83 lines

  1.  
  2. /*
  3.  *   $Id: print.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
  4.  *
  5.  *   This code was written by Craig Southeren whilst under contract
  6.  *   to Computer Sciences of Australia, Systems Engineering Division.
  7.  *   It has been kindly released by CSA into the public domain.
  8.  *
  9.  *   Neither CSA or me guarantee that this source code is fit for anything,
  10.  *   so use it at your peril. I don't even work for CSA any more, so
  11.  *   don't bother them about it. If you have any suggestions or comments
  12.  *   (or money, cheques, free trips =8^) !!!!! ) please contact me
  13.  *   care of geoffw@extro.ucc.oz.au
  14.  *
  15.  */
  16.  
  17. #include "machdep.h"
  18. #include "defs.h"
  19.  
  20. #include "print.h"
  21. #include "paper.h"
  22. #include "postscri.h"
  23. #include "main.h"
  24.  
  25. /********************************
  26.   defines
  27.  ********************************/
  28. #define    PAGEBREAK    ('L' - 0x40)
  29.  
  30.  
  31. /********************************
  32.   print_file
  33.  ********************************/
  34.  
  35. void print_file (input, output, filename, line_numbers)
  36.  
  37. FILE *input;
  38. FILE *output;
  39. char *filename;
  40. int  line_numbers;
  41.  
  42. {
  43.   char line[8192+1];
  44.   int touched = False;
  45.   char *p;
  46.   long line_num = 1;
  47.   char *buffer;
  48.   int  bufflen;
  49.  
  50.   buffer  = line;
  51.   bufflen = 8192;
  52.  
  53.   if (line_numbers) {
  54.     buffer  += 8;
  55.     bufflen -= 8;
  56.     sprintf (line, "%7lu:", line_num);
  57.   }
  58.  
  59.   StartDocument (output, filename);
  60.  
  61.   while (fgets (buffer, bufflen, input) != NULL) {
  62.  
  63.     /* remove the trailing newline from the line */
  64.     buffer [strlen(buffer)-1] = 0;
  65.  
  66.     /* if the line is a page break, then handle it */
  67.     for (p = buffer; *p == ' ' || *p == '\t'; p++)
  68.       ;
  69.     if (*p == PAGEBREAK) {
  70.       if (touched)
  71.         EndColumn (output);
  72.     } else {
  73.       WriteLine (output, line);
  74.       touched = True;
  75.       line_num++;
  76.     }
  77.     if (line_numbers)
  78.       sprintf (line, "%7lu:", line_num);
  79.   }
  80.  
  81.   EndDocument (output);
  82. }
  83.